package  
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BlendMode;
	import flash.display.Sprite;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	/**
	 * @author Nicolas Barradeau
	 * http://en.nicoptere.net
	 */
	public class TestGrain extends Sprite
	{
		
		public function TestGrain()
		
		static public function compute( input:Bitmap, scale:Number = 1, alpha:Number = 1, greyscale:Boolean = false, smooth:Boolean = true ):void
		{
			
			if ( scale > 1 ) scale = 1;
			
			var bd:BitmapData = input.bitmapData.clone();
			
			//bd.noise( 0, 0, 0xFF, 7, greyscale );
			
			bd.perlinNoise( 5, 5, 1, Math.random() * 0xFFFFFF, false, true, 7, greyscale );
			
			input.bitmapData.draw( bd, new Matrix( 1 / scale, 0, 0, 1 / scale ), new ColorTransform( 1,1,1, alpha ), BlendMode.OVERLAY, null, smooth );
			
			
		}
	}

}